{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python_defaultSpec_1595332720718",
   "display_name": "Python 3.7.4 64-bit ('tensorflow': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 填充与复制\n",
    "import tensorflow as tf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = tf.reshape(tf.range(9),[3,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<tf.Tensor: shape=(5, 5), dtype=int32, numpy=\narray([[0, 0, 0, 0, 0],\n       [0, 0, 1, 2, 0],\n       [0, 3, 4, 5, 0],\n       [0, 6, 7, 8, 0],\n       [0, 0, 0, 0, 0]])>"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "tf.pad(a,[[1,1],[1,1]])  # 行(上、下),列(左、右) , 上下左右各Pad一行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<tf.Tensor: shape=(3, 6), dtype=int32, numpy=\narray([[0, 1, 2, 0, 1, 2],\n       [3, 4, 5, 3, 4, 5],\n       [6, 7, 8, 6, 7, 8]])>"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "tf.tile(a,[1,2])  # 在第一个维度保持不变,在第二个维度复制一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<tf.Tensor: shape=(6, 3), dtype=int32, numpy=\narray([[0, 1, 2],\n       [3, 4, 5],\n       [6, 7, 8],\n       [0, 1, 2],\n       [3, 4, 5],\n       [6, 7, 8]])>"
     },
     "metadata": {},
     "execution_count": 6
    }
   ],
   "source": [
    "tf.tile(a,[2,1])  # 在第一个维度复制一次,在第二个维度保持不变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<tf.Tensor: shape=(6, 6), dtype=int32, numpy=\narray([[0, 1, 2, 0, 1, 2],\n       [3, 4, 5, 3, 4, 5],\n       [6, 7, 8, 6, 7, 8],\n       [0, 1, 2, 0, 1, 2],\n       [3, 4, 5, 3, 4, 5],\n       [6, 7, 8, 6, 7, 8]])>"
     },
     "metadata": {},
     "execution_count": 7
    }
   ],
   "source": [
    "tf.tile(a,[2,2])  # 两个维度都复制一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "<tf.Tensor: shape=(2, 3, 3), dtype=int32, numpy=\narray([[[0, 1, 2],\n        [3, 4, 5],\n        [6, 7, 8]],\n\n       [[0, 1, 2],\n        [3, 4, 5],\n        [6, 7, 8]]])>"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "tf.broadcast_to(a,[2,3,3])"
   ]
  }
 ]
}